package com.ruoyi.web.controller.durian;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.durian.service.LlMapService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * 地图控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/map")
public class MapController extends BaseController {

    @Resource
    private LlMapService llMapService;

    /**
     * 初始化地图
     *
     * @return
     */
    @GetMapping("/init/map")
    public AjaxResult initMap() {
        return llMapService.initMap();
    }

    /**
     * 查询半径内的地点
     *
     * @param range 半径
     * @param mapX  当前位置的横坐标
     * @param mapY  当前位置的纵坐标
     * @return
     */
    @GetMapping("/selectRadiusByAddress")
    public AjaxResult selectRadiusByAddress(Integer range, String mapX, String mapY) {
        return llMapService.selectRadiusByAddress(range, mapX, mapY);
    }

    /**
     * 计算预计到达
     *
     * @param startAddressId 开始地点
     * @param endAddressId   结束地点
     * @return
     */
    @GetMapping("/howOver")
    public AjaxResult howOver(Integer startAddressId, Integer endAddressId) {
        return AjaxResult.success(llMapService.howOver(startAddressId, endAddressId));
    }

    /**
     * 检索地点
     *
     * @param keyWord
     * @return
     */
    @GetMapping("/searchAddress")
    public TableDataInfo searchAddress(String keyWord) {
        startPage();
        return getDataTable(llMapService.searchAddress(keyWord));
    }
}
